package com.atguigu.linkedlist_01;

import java.util.Stack;

//演示栈Stack的基本使用
public class TestStack {

	public static void main(String[] args) throws InterruptedException {



	}

}
class  ListNode{
	int val;
	ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
class Solution {
	public ListNode reverseList(ListNode head) {
		if(head.next==null)
			return null;
		Stack<Integer> stack = new Stack<>();
		ListNode listNode = head.next;
		while (listNode!=null){
			int temp = listNode.val;
			stack.push(temp);
			listNode = listNode.next;
		}
		while (stack.empty()==false){
			ListNode listNode1 = head.next;
			listNode1.val = stack.pop();
			listNode1 = listNode1.next;
		}
		return head;
	}
}
